class ValidationError(Exception):
    code_message_dict = {
        401: "没有令牌",
        10001: "用户已存在",
        10002: "用户不存在",
        10003: "两次密码不一致",

        20001: '参数有误',
        20002: "用户名或密码有误",

        30001: "网关名已存在",
        30002: "网关不存在",
        30003: "网关ID已存在",

        40001: "没有令牌或令牌过期",

        50001: "已存在该脚本库",
        50002: "没有文件上传",
        50003: "该脚本库不存在",
        50004: "文件不存在",

        60001: "文件无法展示",
        60002: "文件读写错误",
        60003: "格式化配置文件失败",
        60004: "读取配置文件失败",

        70001: "上传文件失败",
        70002: "下载文件失败",
        70003: "升级文件不存在",

        80001: "任务不存在",
        80002: "传感器id出现重复",
        80003: "设备断线无法添加任务",

        90001: "emqx服务器出错",
        90002: "访问emqx出错",

        11001: "sim卡号为空",
        11002: "刷新网关状态出错",

        12001: "文件已存在",
        12002: "文件不存在",
        12003: "文件使用中无法删除",
        12004: "文件使用中无法上传替换"

    }

    def __init__(self, code):
        self.code = code

    @classmethod
    def get_msg(cls, code):
        return cls.code_message_dict.get(code)


class ConnectionException(Exception):
    def __init__(self):
        super(ConnectionException, self).__init__()
        self.msg = "连接mqtt服务器失败"

    def get_msg(self):
        return self.msg


class PubMessageException(Exception):
    def __init__(self):
        super(PubMessageException, self).__init__()
        self.msg = "发布信息失败"

    def get_msg(self):
        return self.msg


class RightException(Exception):
    def __init__(self):
        super(RightException, self).__init__()
        pass


class TimeOutException(Exception):
    def __init__(self):
        super(TimeOutException, self).__init__()
        self.msg = "网关错误超时"


class RecvOutException(Exception):
    def __init__(self):
        super(RecvOutException, self).__init__()
        self.msg = "订阅网关消息超时"

class NoConnectException(Exception):
    def __init__(self):
        super(NoConnectException, self).__init__()
        self.msg = "设备不在线"


class GatewayException(Exception):
    def __init__(self, resp):
        super(GatewayException, self).__init__()
        self.msg = "".join(["网关返回异常码", resp])

class CNException(Exception):
    def __init__(self, resp):
        super(CNException, self).__init__()
        self.msg = "".join(["中国移动访问出错", resp])

class CNTokenException(Exception):
    def __init__(self, resp):
        super(CNTokenException, self).__init__()
        self.msg = "".join(["中国移动token获取出错", resp])

